package com.devshephard.rpcframework.rpc.enums;

/**
 * 请求方式
 */
public enum RequestType {

    TCP(0, "TCP"),  //使用基于Netty的Tcp远程过程调用
    HTTP(1, "HTTP"); //使用基于HttpClient的远程过程调用


    private Integer type;//类型
    private String desc;//描述

    RequestType(Integer type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public Integer getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public static String getNameByType(Integer type) {
        RequestType[] columns = values();
        for (RequestType column : columns) {
            if (column.getType().equals(type))
                return column.name();
        }
        return null;
    }

    public static String getDescriptionByType(Integer type) {
        RequestType[] columns = values();
        for (RequestType column : columns) {
            if (column.getType().equals(type))
                return column.getDesc();
        }
        return null;
    }

    public static Integer getTypeByDescription(String desc) {
        RequestType[] columns = values();
        for (RequestType column : columns) {
            if (column.getDesc().equals(desc))
                return column.getType();
        }
        return null;
    }

}
